home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 February: Tool Chest / Dev.CD Feb 00 TC.toast / pc / tool chest / development kits / hypercard related / xcmds & xfcns / byrne's xcmds&xfcns / source / getramcache.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-17  |  3.4 KB  |  144 lines

  1. /*
  2.  
  3.     GetRAMCache XFCN v1.1
  4.     
  5.     ©1990-1 Apple Computer, Inc.; by Mike Byrne
  6.     
  7.     This XFCN returns the value set in PRAM for the RAM cache.  If the RAM cache is turned off, it
  8.     returns 0.  Otherwise, it returns the value of the cache.  It can only be described as evil code.
  9.     
  10.     Form:
  11.     GetRAMCache()
  12.     
  13.     # the MPW 3.2 build commands:
  14.     C -b GetRAMCache.c -mbg off
  15.         Link -w -t STAK -c WILD -rt XFCN=609 ∂
  16.             -m ENTRYPOINT ∂
  17.             -sg RamCache ∂
  18.             GetRAMCache.c.o ∂
  19.             "{Libraries}HyperXLib.o" ∂
  20.             "{Libraries}Runtime.o" ∂
  21.             "{Libraries}Interface.o" ∂
  22.             "{CLibraries}StdCLib.o" ∂
  23.             -o "teststack"
  24. */
  25.  
  26. #include <Types.h>
  27. #include <Packages.h>
  28. #include <string.h>
  29. #include <Memory.h>
  30. #include <OSUtils.h>
  31. #include "HyperXCmd.h"
  32.  
  33. #define NULL (long) 0
  34. #define NIL (long) 0
  35.  
  36. #define kNumParams 0
  37.  
  38.  
  39. /* prototypes */
  40. void ErrorBack(XCmdPtr paramPtr, char *message);
  41. void MoveLockParams ( XCmdPtr paramPtr, short paramCount );
  42. void UnlockParams  ( XCmdPtr paramPtr, short paramCount );
  43.  
  44.  
  45.  
  46. pascal void EntryPoint(XCmdPtr paramPtr)
  47. {
  48.     /* variable declarations */
  49.     Byte*            pRam;
  50.     short            cacheSize;
  51.     short            cacheOn;
  52.     Str255            retString;
  53.  
  54.     /* move high and lock the parameters. */
  55.     MoveLockParams(paramPtr, paramPtr->paramCount);
  56.  
  57.     /* check for copyright or syntax help request */
  58.     if (!strcmp( (char*)*paramPtr->params[0], "!") ) {
  59.         ErrorBack(paramPtr, "v1.1, ©1990 Apple Computer, Inc.; by Mike Byrne");
  60.         UnlockParams(paramPtr, paramPtr->paramCount);
  61.         return;
  62.     } else if (!strcmp ( (char*)*paramPtr->params[0], "?") ) {
  63.         ErrorBack(paramPtr, "GetRamCache syntax is 'GetRAMCache()");
  64.         UnlockParams(paramPtr, paramPtr->paramCount);
  65.         return;
  66.     }
  67.  
  68.     /* not a copyright or help request.       */     
  69.     /* check for correct number of parameters */
  70.     if (paramPtr->paramCount != kNumParams) {
  71.         ErrorBack(paramPtr, "Error: GetRamCache syntax is 'GetRAMCache()'");
  72.         UnlockParams(paramPtr, paramPtr->paramCount);
  73.         return;
  74.     }
  75.  
  76.     /* set the address and get values.  How does this really work?  pRam is a pointer to a byte.
  77.        The byte that specifies the RAM cache size is at 0x020A (hex), so the pointer is set to 
  78.        that.  Then, the pointer is incremented one and the byte is masked to get the bit that
  79.        specifies if the cache is on or off.  Yeah, it's ugly.  */
  80.        
  81.     (long) pRam = 0x020A;
  82.     cacheSize = (*pRam)*32;
  83.     NumToString(cacheSize, retString);
  84.     p2cstr(retString);
  85.     pRam++;
  86.     cacheOn = (*pRam) &  0x20;
  87.     if (!cacheOn) {
  88.         ErrorBack(paramPtr, "0");
  89.         return;
  90.     }     
  91.     ErrorBack(paramPtr, retString);
  92.     return;
  93.  
  94. }
  95.  
  96.  
  97.  
  98.  
  99.  
  100.     
  101. /* allocate and load up paramPtr->returnValue with a string 
  102.    -------------------------------------------------------- */
  103. void ErrorBack(XCmdPtr paramPtr, char *message)
  104. {
  105.     Handle  mesHnd;
  106.  
  107.     /*
  108.         Allocate space for an error message.
  109.         Copy the string into it.
  110.         Return the handle to HyperCard.
  111.     */
  112.     mesHnd = NewHandle((long)(strlen(message)+1));
  113.     if (mesHnd == nil) return;
  114.     strcpy((char *)*mesHnd,message);
  115.     paramPtr->returnValue = mesHnd;
  116. }
  117.  
  118.  
  119.  
  120. /*  move high and lock down all parameters  
  121.     ----------------------------------------------------------------------- */
  122. void MoveLockParams ( XCmdPtr paramPtr, short paramCount )
  123. {
  124.     short i;
  125.     
  126.     for(i=0; i <= paramCount-1; i++)
  127.     {
  128.         MoveHHi(paramPtr->params[i]);
  129.         HLock(paramPtr->params[i]);
  130.     }
  131. }
  132.  
  133.  
  134.  
  135.  
  136. /* unlock all parameter handles in the XCmdBlock  
  137.    ---------------------------------------------  */
  138. void UnlockParams  ( XCmdPtr paramPtr, short paramCount )
  139. {    short i;
  140.     
  141.     for(i=0; i <= paramCount-1; i++)
  142.         { HUnlock(paramPtr->params[i]);}
  143. }
  144.